package org.etom.impl.ui.wizards;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

/**
 * The abstract class initializes the GUI for the given wizard page.
 */
public abstract class AbstractDownloadAsNewProjectPage extends WizardPage {

  private static final String PAGE_NAME = "DownloadAsNewProjectWizardPage"; //$NON-NLS-1$
  
  private Composite composite;
  protected Button useDefaultLocationButton;
  protected Text locationText;
  protected Button browseButton;
  
  protected AbstractDownloadAsNewProjectPage() {
    super(PAGE_NAME);
  }

  /**
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  @Override
  public void createControl(Composite parent) {
    initComposite(parent);
    addControls();
    initPage();
  }

  /*
   * Creates the composite.
   */
  private void initComposite(Composite parent) {
    this.composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    this.composite.setLayout(layout);
  }
  
  /*
   * The method adds the page controls.
   */
  private void addControls() {
    //add button
    this.useDefaultLocationButton = new Button(composite, SWT.CHECK);
    GridData gridData = new GridData();
    gridData.horizontalSpan = 3;
    this.useDefaultLocationButton.setLayoutData(gridData);
    this.useDefaultLocationButton.setText(
        WizardsMessages.DownloadAs_NewProjectPage_UseDef_Button);
    
    //add location controls
    //*label
    Label locationLabel = new Label(this.composite, SWT.NONE);
    locationLabel.setText(
        WizardsMessages.DownloadAs_NewProjectPage_Location_Label);
    //*location text field
    locationText = new Text(composite, SWT.BORDER);
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = SWT.FILL;
    locationText.setLayoutData(gridData);
    //*browse button
    browseButton = new Button(composite, SWT.NONE);
    browseButton.setText(
        WizardsMessages.DownloadAs_NewProjectPage_Browse_Button);
  }
  
  /*
   * Initializes the page.
   */
  private void initPage() {
    setControl(composite);
    setTitle(
        WizardsMessages.DownloadAs_NewProjectPage_Title);
    setDescription(
        WizardsMessages.DownloadAs_NewProjectPage_Description);
  }
  
}
